Creating a Complex Polygon
This example demonstrates how to create a polygon based on a multipolygon geometry and set its properties. This example uses the IGeometryCreator (CreateGeometryFromWKT, CreateLinearRingGeometry, CreatePolygonGeometry) and ICreator81 (CreatePolygon, CreateColor, GeometryCreator), IPosition81 (Distance, Pitch) and INavigate81 (FlyTo) properties and methods.
function ComplexPolygon()
{
try
{
// Create polygon with hole geometry from well-known-text
var complexGeometry1 = sgworld.Creator.GeometryCreator.CreateGeometryFromWKT("POLYGON((-81.900091 26.739261,-81.906338 26.840896,-81.591731 26.951601,-81.819248 26.717179,-81.900091 26.739261),(-81.873569 26.819371,-81.81616 26.772908,-81.811242 26.846308,-81.873569 26.819371))");
// Create polygon
// Create line color using creator by specifying red,green,blue,alpha values
var lineColor1 = sgworld.Creator.CreateColor(255, 0, 0, 0);
var fillColor1 = "#00ff00"; // we can also specify color using HTML notation
var polygon1 = sgworld.Creator.CreatePolygon(complexGeometry1, lineColor1, fillColor1, 2 /*AltitudeTypeCode.ATC_ON_TERRAIN*/, "", "Polygon with hole");
// create multipolygon from array of x,z,y points
// Polygon geometry consists of LinearRing that specifies exterior ring and array of LinearRing geometries that specify interior rings
// create exterior ring using array of coordinates
var exteriorRing = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry([-81.593456, 26.692189, 1000, -81.569379, 26.654723, 2000, -81.482195, 26.724591, 1000, -81.55208, 26.771137, 1000]);
var interiorRing1 = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry([-81.577327, 26.713192, 1000, -81.568101, 26.726351, 1000, -81.569138, 26.715869, 1000]);
var interiorRing2 = sgworld.Creator.GeometryCreator.CreateLinearRingGeometry([-81.55315, 26.691784, 2000, -81.555867, 26.673088, 2000, -81.5252610, 26.688447, 2000]);
var complexGeometry2 = sgworld.Creator.GeometryCreator.CreatePolygonGeometry(exteriorRing, [interiorRing1,interiorRing2 ] );
var fillColor2 = "#0000ff";
var lineColor2 = "#00ff00";
// Create polygon
var polygon2 = sgworld.Creator.CreatePolygon(complexGeometry2, lineColor2, fillColor2, 3 /* AltitudeTypeCode.ATC_TERRAIN_ABSOLUTE */, "", "Polygon with 2 holes");
polygon2.Position.Distance = 81000;
polygon2.Position.Pitch = -45;
sgworld.Navigate.FlyTo(polygon2.Position);
}
catch(e)
{
alert("Unexpected error:" + ex.description);
}
}